var validationRules = require("./validationRules");
module.exports.hasError = function(formData){
	return (typeof formData["errors"] !== "undefined");
}


module.exports.validate = function(validations, formData, field, value){
	var hasError = false;
	var rules = validationRules.getValidationRules( validations );
	
		if(typeof rules[field] !== "undefined"){
			if(rules[field] == "required"){
				if(value == null || value == ""){
					formData["error_in_" + field] = field + " is required";
					hasError = true;
					if(typeof formData["errors"] == "undefined"){
						formData["errors"] = {};
					}
					//record errors
					formData["errors"][field] =  field + " is required";
				}
			}else{
				formData["error_in_" + field] = "";
			}
			
		}
		/*else{
			formData["error_in_" + field] = "";//NO ERROR
		}*/
		
		
		if(hasError){
			formData["has_error"] = true;
		}
		
	return formData;
}